// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexLifecycleManagement;

public sealed partial class Phase
{
	[JsonInclude, JsonPropertyName("actions")]
	public object? Actions { get; set; }
	[JsonInclude, JsonPropertyName("configurations")]
	public Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Configurations? Configurations { get; set; }
	[JsonInclude, JsonPropertyName("min_age")]
	public Union<Elastic.Clients.Elasticsearch.Duration, long>? MinAge { get; set; }
}

public sealed partial class PhaseDescriptor : SerializableDescriptor<PhaseDescriptor>
{
	internal PhaseDescriptor(Action<PhaseDescriptor> configure) => configure.Invoke(this);

	public PhaseDescriptor() : base()
	{
	}

	private object? ActionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Configurations? ConfigurationsValue { get; set; }
	private Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ConfigurationsDescriptor ConfigurationsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ConfigurationsDescriptor> ConfigurationsDescriptorAction { get; set; }
	private Union<Elastic.Clients.Elasticsearch.Duration, long>? MinAgeValue { get; set; }

	public PhaseDescriptor Actions(object? actions)
	{
		ActionsValue = actions;
		return Self;
	}

	public PhaseDescriptor Configurations(Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Configurations? configurations)
	{
		ConfigurationsDescriptor = null;
		ConfigurationsDescriptorAction = null;
		ConfigurationsValue = configurations;
		return Self;
	}

	public PhaseDescriptor Configurations(Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ConfigurationsDescriptor descriptor)
	{
		ConfigurationsValue = null;
		ConfigurationsDescriptorAction = null;
		ConfigurationsDescriptor = descriptor;
		return Self;
	}

	public PhaseDescriptor Configurations(Action<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ConfigurationsDescriptor> configure)
	{
		ConfigurationsValue = null;
		ConfigurationsDescriptor = null;
		ConfigurationsDescriptorAction = configure;
		return Self;
	}

	public PhaseDescriptor MinAge(Union<Elastic.Clients.Elasticsearch.Duration, long>? minAge)
	{
		MinAgeValue = minAge;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ActionsValue is not null)
		{
			writer.WritePropertyName("actions");
			JsonSerializer.Serialize(writer, ActionsValue, options);
		}

		if (ConfigurationsDescriptor is not null)
		{
			writer.WritePropertyName("configurations");
			JsonSerializer.Serialize(writer, ConfigurationsDescriptor, options);
		}
		else if (ConfigurationsDescriptorAction is not null)
		{
			writer.WritePropertyName("configurations");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ConfigurationsDescriptor(ConfigurationsDescriptorAction), options);
		}
		else if (ConfigurationsValue is not null)
		{
			writer.WritePropertyName("configurations");
			JsonSerializer.Serialize(writer, ConfigurationsValue, options);
		}

		if (MinAgeValue is not null)
		{
			writer.WritePropertyName("min_age");
			JsonSerializer.Serialize(writer, MinAgeValue, options);
		}

		writer.WriteEndObject();
	}
}